package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.user.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("新增购物车")
    public Result<String> addCart(@RequestBody ShoppingCartDTO cartDTO){
        log.info("新增购物车--{}", cartDTO);
        return shoppingCartService.addCart(cartDTO);
    }

    @GetMapping("/list")
    @ApiOperation("查询购物车列表")
    public Result<List<ShoppingCart>> list(){
        return shoppingCartService.list();
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result<String> clean(){
        return shoppingCartService.clean();
    }
}
